package me.luck2.wicketcaptcha;

import org.apache.wicket.util.time.Duration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.webapp.WebAppContext;

public class StartWicketCatcha {

	public static void main(final String[] args) throws Exception {
		final int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

		final Server server = new Server();

		final ServerConnector http = new ServerConnector(server);
		http.setIdleTimeout(timeout);
		http.setSoLingerTime(-1);
		http.setPort(8080);
		server.addConnector(http);
		// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
		// org.eclipse.jetty.webapp.Configuration.ClassList classlist =
		// org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
		// classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration",
		// "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");

		final WebAppContext bb = new WebAppContext();
		bb.setServer(server);
		bb.setContextPath("/");
		bb.setWar("src/main/webapp");
		server.setHandler(bb);

		try {
			System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
			server.start();
			System.in.read();
			System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
			server.stop();
			server.join();
		} catch (final Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
